home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2004 #2 / Amiga Plus CD - 2004 - No. 02.iso / AmiSoft / Misc / emu / Wzonka-Lad.lha / Wzonka-Lad / src / rle_packer.s < prev    next >
Text File  |  1999-04-15  |  2KB  |  64 lines

  1.  
  2.         lea    jorma,a0
  3.         lea    jeppe,a1
  4.         move.l    #18528,d0
  5.  
  6. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  7. ;            rle algorithm based data packer
  8. ;
  9. ;        $VER: rle packer v0.1 by teuvo tursas (20-Dec-96)
  10. ;
  11. ;        v0.1        -    the first attempt, fully working
  12. ;                -    .L = unpacked size, .L = packed size,
  13. ;                    .B = byte, .B = amount of it (0<x<255)...
  14. ;                -    packed size = the output data size
  15. ;                    excluding the two first .Ls.
  16. ;
  17. ;                input
  18. ;
  19. ;        d0    =    input data size in bytes.
  20. ;        a0    =    input data area.
  21. ;        a1    =    output data area.
  22. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  23.  
  24. rle_pack:    moveq.l    #0,d1                ;output size in bytes.
  25.                             ;excluding the sizes.
  26.         lea    8(a1),a2            ;a2 = output for data.
  27.         move.l    d0,(a1)+            ;store the unpacked size.
  28. rle_pack_core:    move.b    (a0)+,d3
  29.         move.b    d3,(a2)+            ;store byte.
  30.         moveq.l    #1,d2                ;output rle byte size.
  31.         addq.l    #1,d1                ;one byte larger.
  32.         subq.l    #1,d0                ;one byte smaller.
  33.         beq.s    rle_pack_end            ;end of input.
  34. rle_pack_more:    move.b    (a0)+,d4            ;next byte.
  35.         cmp.b    d4,d3                ;same thing?
  36.         bne.s    rle_pack_miss            ;no. next one.
  37.         addq.b    #1,d2                ;one byte bigger rle size.
  38.         subq.l    #1,d0                ;one byte smaller.
  39.         cmp.b    #$ff,d2                ;the max?
  40.         beq.s    rle_pack_next            ;yes. close this packet.
  41.         tst.l    d0
  42.         beq.s    rle_pack_end            ;end of input.
  43.         bra.s    rle_pack_more
  44. rle_pack_miss:    subq.l    #1,a0                ;the previous byte.
  45. rle_pack_next:    move.b    d2,(a2)+            ;store the rle size byte.
  46.         addq.l    #1,d1                ;one byte larger.
  47.         bra.s    rle_pack_core            ;pack it again.
  48.  
  49. rle_pack_end:    addq.l    #1,d1                ;the last store.
  50.         move.l    d1,(a1)+            ;store the packed length.
  51.         move.b    d2,(a2)+            ;store the last rle size.
  52. rle_pack_exit:    lea    jeppe,a3
  53.         sub.l    a3,a2
  54.         move.l    a2,d0
  55.         rts
  56.  
  57.         section    mur,data
  58.  
  59. jorma:        incbin    "binworld:gameboy/windows/prefs.bn"
  60.         even
  61.         
  62. jeppe:        ds.b    81920
  63.  
  64.